package com.xzakota.minesweeper.msg;

import com.xzakota.minesweeper.model.entity.UserBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 房间排行榜消息
 *
 * @author Xzakota
 */
public class RoomRankMsg extends RoomMsg {
    public List<UserBean> getRank() {
        List<UserBean> list = new ArrayList<>();
        Object[] msg = (Object[]) this.data;
        for (int i = 2; i < msg.length; i++) {
            if (msg[i] instanceof UserBean user) {
                list.add(user);
            }
        }
        return list;
    }

    @Override
    public String getTag() {
        return "房间排行榜消息";
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(getTag() + ": ");

        if (code == MsgCode.BASE_UNKNOWN) {
            sb.append("查询排行榜");
        } else {
            sb.append("房间").append(getRoomNum()).append(" 排行榜: ");

            for (UserBean userBean : getRank()) {
                sb.append(userBean.username).append("-").append(userBean.time).append(" ");
            }
        }
        return sb.toString();
    }
}